class Solution {
    public int longestOnes(int[] nums, int k) {
        int left = 0;
        int right = 0;
        int len = 0;
        int zero = 0;
        while(right < nums.length){
            //进窗口
            if(nums[right] == 0){
                zero++;
            }
            //出窗口
            while(zero > k){
                if(nums[left] == 0){
                    zero--;
                }
                left++;
            }
            //更新结果
            if(len < right - left + 1){
                len = right - left + 1;
            }
            right++;
        }
        return len;
    }
}
